Economic activities in Zürich

Zürich Statistical Office collects data on city and its residents. This data is published as Linked Data.

In this tutorial, we will show how to work with Linked Data. Mainly, we will see how to work with data on economic activities.
We will look into how to query, process, and visualize it.

1. Restaurants over time
2. Restaurants in city quartiers
3. After-school care: gender-representation

SPARQL endpoint

Data on some economic activities is published as Linked Data. It can be accessed with SPARQL queries.
You can send queries using HTTP requests. The API endpoint is https://ld.stadt-zuerich.ch/query/.

Let's use SparqlClient from graphly to communicate with the database. Graphly will allow us to:

SPARQL queries can become very long. To improve the readibility, we will work wih prefixes.

Using add_prefixes method, we define persistent prefixes. Every time you send a query, graphly will add automatically update the prefixes for you.

Restaurants over time

Let's find the number of restaurants in Zurich over time. This information is available in AST-BTA data cube. To give restaurants numbers a context, let's scale them by population size. The number of inhabitants over time can be found in BEW data cube.

The query for number of inhabitants and restaurants over time is:

Let's calculate number of restaurants per 10 000 inhabitants

Restaurants in city quartiers

Let's find the number of restaurants in different part of the city. The data on restaurants is available in AST-BTA data cube. To place the quertiers on the map, we will need their geographic coordinates. This data is available in Wikidata. We will get number of restaurants per district from our endpoint, and quertier centroid from Wikidata.

Both information can be obtained using SPARQL federated query. The endpoint for Wikidata is <https://query.wikidata.org/sparql>.

The query for quertiers, its centroids, and number of restaurants is:

Let's classify the number of restaurants into 5 different buckets. We will use mapclassify library to assign values in restaurant column into one of five categories.

Classified values can be easily visualized on the map.

After-school care: gender-representation

Let's take a look at gender representation in public sector. In BES-BTA-SEX data cube we can find information on number of employees in different organizations. The data is reported separately for each sex, and various establishment types. Let's find the number of male and female employees in after-school care (Hort).

The query for number of female and male employees in after-school care over time is:

Let's rearrange and rename the columns: